package cn.net.chenbao.medical.adapter.radapter;

import android.support.v7.widget.RecyclerView;
import android.util.SparseArray;
import android.view.View;
import android.widget.ImageView;
import android.widget.TextView;

import org.xutils.common.util.DensityUtil;

/**
 * Created by 6-Bubble on 2016/10/12.
 */
public class CommonViewHolder<T> extends RecyclerView.ViewHolder {
    private SparseArray<View> mViews;
    private View mConvertView;
    private T item;

    public CommonViewHolder(View itemView) {
        super(itemView);
        this.mConvertView = itemView;
        mViews = new SparseArray<View>();
    }


    public <T extends View> T getView(int viewId) {
        View view = mViews.get(viewId);
        if (view == null) {
            view = mConvertView.findViewById(viewId);
            mViews.put(viewId, view);
        }
        return (T) view;
    }

    public void setItem(T item) {
        this.item = item;
    }


    //设置Textview的值
    public CommonViewHolder setText(int viewId, String text) {
        TextView tv = getView(viewId);
        tv.setText(text);
        return this;
    }

    public CommonViewHolder setImageResource(int viewId, int resId) {
        ImageView view = getView(viewId);
        view.setImageResource(resId);
        return this;
    }
}
